{% extends "wiki/article.html" %}
{% load wiki_tags i18n sekizai_tags static %}


{% block wiki_pagetitle %}{% trans "History" %}: {{ article.current_revision.title }}{% endblock %}

{% block wiki_contents_tab %}

{% include "wiki/includes/modals.html" %}

{% addtoblock "js" %}
<script type="text/javascript" src="{% static "wiki/js/diffview.js" %}"></script>
<script type="text/javascript" src="{% static "wiki/js/diff.js" %}"></script>
{% endaddtoblock %}
{% addtoblock "css" %}
<style type="text/css">
  td.linenumber {
    width: 20px;
  }
  tr.insert td {
    background-color: #DFC;
  }
  tr.delete td {
    background-color: #FDC;
  }
  tr.equal td {
    background-color: #F2F2F2;
  }

  .diff-container td {
    white-space: pre; font-family: monospace;
  }
  .diff-container td,
  .diff-container th {
    padding: 2px 7px;
    border-right: 1px solid #DDD;
  }
  .diff-container td:last-child,
  .diff-container th:last-child {
    border-right: none;
  }
  .diff-container table {
    border-top: 1px solid #DDD;
  }
</style>
{% endaddtoblock %}

<p class="lead">
  {% trans "Click each revision to see a list of edited lines. Click the Preview button to see how the article looked at this stage. At the bottom of this page, you can change to a particular revision or merge an old revision with the current one." %}
</p>

<form method="GET">
  <div class="tab-content" style="overflow: visible;">
    {% for revision in revisions %}
      <div class="panel-group" id="accordion{{ revision.revision_number }}">
        <div class="panel panel-default">
          <div class="panel-heading">
            <a class="panel-toggle" style="float: left;" href="#collapse{{ revision.revision_number }}" onclick="get_diff_json('{% url 'wiki:diff' revision.id %}', $('#collapse{{ revision.revision_number }}'))">
              {% if revision == article.current_revision %}
                <i class="fa fa-flag"></i>
              {% else %}
                <i class="fa fa-plus"></i>
              {% endif %}
              {% include "wiki/includes/revision_info.html" with current_revision=article.current_revision %}
              <div class="text-muted">
                <small>
                {% if revision.user_message %}
                  {{ revision.user_message }}
                {% elif revision.automatic_log %}
                  {{ revision.automatic_log }}
                {% else %}
                  ({% trans "no log message" %})
                {% endif %}
                </small>
              </div>
            </a>
            <div class="progress progress-striped active" style="display: none; width: 40px; float: left; margin-top: 7px; margin-bottom: -7px;">
              <div class="bar" style="width: 100%;"></div>
            </div>
            <div class="pull-right" style="vertical-align: middle; margin: 8px 8px;">
              {% if revision == article.current_revision %}
              <a href="#" class="btn btn-default disabled">
                <span class="fa fa-lock fa-fw"></span>
                {% trans "Preview this revision" %}
              </a>
              {% else %}
              <button type="submit" class="btn btn-default" onclick="$('#previewModal').modal('show'); this.form.target='previewWindow'; this.form.r.value='{{ revision.id }}'; this.form.action='{% url 'wiki:preview_revision' article.id %}'; $('#previewModal .switch-to-revision').attr('href', '{% url 'wiki:change_revision' path=urlpath.path article_id=article.id revision_id=revision.id %}')">
                <span class="fa fa-eye fa-fw"></span>
                {% trans "Preview this revision" %}
              </button>
              {% endif %}

              {% if article|can_write:user and not article.current_revision.locked %}
              <input type="radio"{% if revision == article.current_revision %} disabled="true"{% endif %} style="margin: 0 10px;" value="{{ revision.id }}" name="revision_id" switch-button-href="{% url 'wiki:change_revision' path=urlpath.path revision_id=revision.id %}" merge-button-href="{% url 'wiki:merge_revision_preview' article_id=article.id revision_id=revision.id %}" merge-button-commit-href="{% url 'wiki:merge_revision' path=urlpath.path article_id=article.id revision_id=revision.id %}" />
              {% endif %}

            </div>
            <div style="clear: both"></div>
          </div>
          <div id="collapse{{ revision.revision_number }}" class="panel-collapse collapse">
            <div class="panel-body diff-container" style="padding: 0;">
              <dl class="dl-horizontal">
                <dt>{% trans "Auto log:" %}</dt>
                <dd>{{ revision.automatic_log|default:"-"|linebreaksbr }}</dd>
              </dl>
              <table class="table table-condensed" style="margin: 0; border-collapse: collapse;">
                <thead>
                  <tr>
                    <th class="linenumber">{% if revision.previous_revision %}#{{revision.previous_revision.revision_number}}{% endif %}</th>
                    <th class="linenumber">#{{revision.revision_number}}</th>
                    <th>{% trans "Change" %}</th>
                  </tr>
                </thead>
              </table>
            </div>
          </div>
        </div>
      </div>
    {% endfor %}

    {% include "wiki/includes/pagination.html" %}

    {% if revisions.count > 1 and article|can_write:user and not article.current_revision.locked %}

    <div class="form-group form-actions">
      <div class="pull-right">
        <button type="submit" name="preview" value="1" class="btn btn-default" onclick="$('#mergeModal').modal('show'); this.form.target='mergeWindow'; this.form.action=$('input[type=radio]:checked').attr('merge-button-href'); $('.merge-revision-commit').attr('href', $('input[type=radio]:checked').attr('merge-button-commit-href'))">
          <span class="fa fa-random"></span>
          {% trans "Merge selected with current..." %}
        </button>
        <button type="submit" name="save" value="1" class="btn btn-primary" onclick="this.form.target='_self'; this.form.action=$('input[type=radio]:checked').attr('switch-button-href')">
          <span class="fa fa-flag"></span>
          {% trans "Switch to selected version" %}
        </button>
      </div>
      <div style="clear:both"></div>
    </div>

    {% endif %}

  </div>
  <input type="hidden" name="r" value="" />
  <div class="modal fade wiki-modal" id="previewModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-body">
          <iframe name="previewWindow" frameborder="0"></iframe>
        </div>
        <div class="modal-footer">
          <a href="#" class="btn btn-default btn-lg" data-dismiss="modal">
            <span class="fa fa-arrow-circle-left"></span>
            {% trans "Back to history view" %}
          </a>
          {% if article|can_write:user %}
          <a href="#" class="btn btn-lg btn-primary switch-to-revision">
            <span class="fa fa-flag"></span>
            {% trans "Switch to this version" %}
          </a>
          {% else %}
            <a href="#" class="btn btn-lg btn-primary disabled">
              <span class="fa fa-lock"></span>
              {% trans "Switch to this version" %}
            </a>
          {% endif %}
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade wiki-modal" id="mergeModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h1>{% trans "Merge with current" %}</h1>
          <p class="lead"><span class="fa fa-info-circle"></span> {% trans "When you merge a revision with the current, all data will be retained from both versions and merged at its approximate location from each revision." %} <strong>{% trans "After this, it's important to do a manual review." %}</strong></p>
        </div>
        <div class="modal-body">
          <iframe name="mergeWindow" frameborder="0" style="min-height: 0;"></iframe>
        </div>
        <div class="modal-footer">
          <a href="#" class="btn btn-default btn-lg" data-dismiss="modal">
            <span class="fa fa-arrow-circle-left"></span>
            {% trans "Back to history view" %}
          </a>
          {% if article|can_write:user %}
          <a href="#" class="btn btn-lg btn-primary merge-revision-commit">
            <span class="fa fa-file"></span>
            {% trans "Create new merged version" %}
          </a>
          {% else %}
            <a href="#" class="btn btn-lg btn-primary disabled">
              <span class="fa fa-lock"></span>
              {% trans "Create new merged version" %}
            </a>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</form>

{% endblock %}
